<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<script language="javascript">
<!--
	$(function() {
		
		$("#parent").ligerComboBox({
			width : 215,
			selectBoxWidth : 215,
			selectBoxHeight : 180,
			valueField : 'id',
			textField : 'text',
			treeLeafOnly : false,
			tree : {
				checkbox : false,
				btnClickToToggleOnly : false,
				url : '/misc/cms/channelTree.htm'
			}
		});
		if("${parentId}" != "undefined"){
			$("#parent_val").val("${parentId}");
		}
		
	});

	//添加频道
	function addChannel() {
		var parent = $("#parent").ligerGetComboBoxManager().getValue();
		var mark = $.trim($("#mark").val());
		var name = $.trim($("#name").val());
		if(parent==""){
			$.ligerDialog.warn("请选择父频道！");
			return;
		}else if(name==""){
			$.ligerDialog.warn("请填写频道名称！");
			return;
		}
		$("#addChannel").attr("onclick","");
		$.post("/misc/cms/addChannel.htm", {
			mark : mark,
			name : name,
			parent : parent
		}, function(data) {
			if (data == "success") {
				$.ligerDialog.success("添加成功！");
			}else if(data == "sameMark"){
				$.ligerDialog.warn("该频道标识已经有了，系统已帮您重置！");
			}else{
				$.ligerDialog.warn("系统有点抽经，请稍候重试！");
			}
			//重新生成频道标识符
			$.get("/misc/cms/buildUUID.htm",function(data){$("#mark").val(data);});
			$("#addChannel").attr("onclick","addChannel()");
		});
	}
	
	//设置为根目录
	function setRootParent(){
		$('#parent').val('根目录');
		$('#parent_val').val('0');
	}
//-->
</script>
<style>
	.def_t td{border:1px solid #ccc; padding:5px;}
	
</style>
<table width="100%" class="def_t">
	<tr>
		<td>频道ID：</td>
		<td><input type="text" id="mark" value="${mark }" disabled="disabled" style="border:1px solid #a3c0e8; padding:3px 5px;width: 400px;">
		</td>
	</tr>
	<tr>
		<td>名称：</td>
		<td><input type="text" id="name" style="border:1px solid #a3c0e8; padding:3px 5px;width: 400px;">
		</td>
	</tr>
	<tr height="30">
		<td>父频道：</td>
		<td>
			<input type="text" id="parent"/><button onclick="setRootParent()">根目录</button>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
			<button type="button" style="padding:2px 20px;" id="addChannel" onclick="addChannel()">保存</button>
		</td>
	</tr>
</table>


